<template>
  <div class="book-detail">
    <t-card :bordered="false" class="content-card">
      <template #title>
        <t-space size="18px">
          <h2 class="card-title">调拨订单表</h2>
          <icon-font name="chevron-down-circle" />
          <t-link class="edit-btn-color" hover="color">编辑</t-link>
        </t-space>
      </template>
      <template #actions>
        <t-space size="8px">
          <t-button @click="handleWarehousing" class="add-btn">
            <p class="flex align-center">
              <i class="iconfont icon-outbound" style="font-size: 24px;margin-right: 4px"></i>调拨
            </p>
          </t-button>
        </t-space>
      </template>

      <div class="filter ">
        <t-space size="12px">
          <!--<t-select style="width: 140px;" v-model="params.order_type" :options="typeOptions" clearable @change="getData" placeholder="按订单类型">-->
          <!--  <template #label>-->
          <!--    <icon-font name="layers" style="color: #000;"/>-->
          <!--  </template>-->
          <!--</t-select>-->
          <t-select style="width: 140px;" v-model="params.is_del" :options="statusOptions" clearable @change="getData" placeholder="按订单状态">
            <template #label>
              <icon-font name="layers" style="color: #000;"/>
            </template>
          </t-select>
          <t-input style="width: 260px;" v-model="params.key" clearable @change="getData" placeholder="搜索：单号/批号/联系人/经办人">
            <template #label>
              <icon-font name="search" size="16px" style="color:#000;font-weight: bold"/>
            </template>
          </t-input>
        </t-space>
      </div>

      <div class="pt16">
        <t-table
          rowKey="id"
          :data="lists"
          :columns="columns"
          :stripe="stripe"
          :bordered="bordered"
          :hover="hover"
          :size="size"
          :max-height="maxHeight"
          :table-layout="tableLayout ? 'auto' : 'fixed'"
          :showHeader="showHeader"
          cellEmptyContent="-"
          resizable
          :loading="loading"
          @page-change="pageChange"
          :pagination="pagination"
          :selected-row-keys="selectedRowKeys"
          @select-change="handleSelectChange"
        >
          <template #title-slot-option></template>
          <template #thumb="{row}">
            <t-image-viewer :images="[row.thumb]" :closeOnEscKeydown="false">
              <template #trigger="{ open }">
                <div class="tdesign-demo-image-viewer__ui-image" @click="open">
                  <p class="prod-img">
                    <!--<img alt="test" :src="row.thumb"/>-->
                    <img alt="图片" src="@/assets/product.png" />
                  </p>
                  <div class="tdesign-demo-image-viewer__ui-image--hover">
                    <span><browse-icon size="1.4em"/> 预览</span>
                  </div>
                </div>
              </template>
            </t-image-viewer>
          </template>
          <template #order_type="{row}">
            <!--（0入库；1 出库；2 调拨；）-->
            <p v-if="row.order_type === 0">入库</p>
            <p v-if="row.order_type === 1">出库</p>
            <p v-if="row.order_type === 2">调拨</p>
            <p v-if="row.order_type === 3">盘点</p>
          </template>
          <template #discount_amount="{row}">
            <p>￥{{ row.discount_amount ? row.discount_amount : '0.00' }}</p>
          </template>
          <template #option="{row}">
            <t-space size="12px">
              <t-link theme="primary" class="edit-btn-color" hover="color" @click="handleEdit(row)">编辑</t-link>
              <t-link theme="primary" class="edit-btn-color" hover="color" @click="handleInfo(row)">详情</t-link>
              <t-popconfirm theme="danger" placement="top-right" confirm-btn="删除" @confirm="handleDelete($event, row)">
                <template #content>
                  <div>
                    <h3 class="popconfirm-title">确认删除？</h3>
                    <p>删除后数据将不可以恢复！是否确认删除？</p>
                  </div>
                </template>
                <t-link theme="danger" variant="outline" hover="color">删除</t-link>
              </t-popconfirm>
            </t-space>
          </template>
        </t-table>
      </div>
    </t-card>
    <div v-if="selectedRowKeys?.length" class="footer">
      <t-space size="12px">
        <t-popconfirm theme="danger" confirm-btn="删除">
          <template #content>
            <div>
              <h3 class="popconfirm-title">确认批量下架？</h3>
            </div>
          </template>
          <t-button theme="default" variant="outline">下架</t-button>
        </t-popconfirm>
        <t-button theme="default" variant="outline">上架</t-button>
      </t-space>
      <t-space size="12px">
        <p class="flex align-center">库存总数：<span class="expenditure">820</span></p>
        <p class="flex align-center">已出库：<span class="income">290</span></p>
      </t-space>
    </div>

    <product-add ref="add" @refresh="getData"></product-add>

    <!-- 订单详情 -->
    <order-info ref="info"></order-info>
  </div>
</template>

<script lang="jsx">
import {IconFont, CalendarIcon, BrowseIcon} from "tdesign-icons-vue";
import IconUAV from "@/components/icon-UAV/index.vue";
import ProductAdd from "@/pages/warehouse/allocation/add/index.vue";
import {warehouse_orderDeleteApi, warehouse_orderListApi} from "@/api/InOutStorage";
import OrderInfo from "@/pages/warehouse/allocation/components/order-info.vue";

export default {
  name: 'Warehousing',
  components: {OrderInfo, IconUAV, IconFont, BrowseIcon, ProductAdd},
  data() {
    return {
      renderPrefixIcon: () => <CalendarIcon/>,
      params: {
        page: 1,  // 当前页
        limit: 10,  // 每页条数
        order_type: 2, // 订单类型（0入库；1出库；2调拨；3盘点）
        key: '',  // 搜索：单号/批号/联系人/经办人
        is_del: '', // 状态
      },
      lists: [],
      size: 'medium',
      tableLayout: false,
      stripe: false,
      bordered: false,
      hover: true,
      showHeader: true,
      columns: [
        //{colKey: 'row-select', type: 'multiple', width: 40,},
        //{colKey: 'thumb', title: '图片', align: 'center', width: 60,},
        //{colKey: 'warehouse_id', title: '产品名称', width: 240, ellipsis: true},
        //{colKey: 'next_warehouse_id', title: '进货价', width: 120},
        {colKey: 'order_type', title: '订单类型', width: 90},
        {colKey: 'order_no', title: '单号', width: 180},
        {colKey: 'product_count', title: '产品数', width: 140},
        {colKey: 'discount_amount', title: '总优惠金额', width: 140},
        {colKey: 'linkman', title: '联系人', width: 140},
        {colKey: 'phone', title: '联系电话', width: 140},
        {colKey: 'operator_name', title: '经办人', width: 140},
        {colKey: 'order_date', title: '订单日期', width: 140},
        {colKey: 'creation_time', title: '创建时间', width: 180},
        {colKey: 'update_time', title: '更新时间', width: 220},
        {colKey: 'option', title: 'title-slot-option', fixed: 'right', width: 140},
      ],
      selectedRowKeys: [],
      pagination: {
        defaultCurrent: 1,
        defaultPageSize: 20,
        total: 0,
      },
      maxHeight: 472,
      loading: false,

      typeOptions: [
        //（0 入库；1 出库；2 调拨；）
        { label: '入库', value: 0 },
        { label: '出库', value: 1 },
        { label: '调拨', value: 2 },
      ],
      statusOptions: [
        { label: '正常', value: 0 },
        { label: '回收站', value: 1 },
      ],
    };
  },
  computed: {
    //...mapState('book', ['bookId'])
  },
  mounted() {
    let height = document.documentElement.clientHeight - 244;
    this.maxHeight = height
    window.onresize = () => {
      // 获取屏幕高度 - 顶部高度
      height = document.documentElement.clientHeight - 244;
      this.maxHeight = height
    };

    this.getData()
  },
  methods: {
    // 入库
    handleWarehousing() {
      this.$refs.add.open('add')
    },
    // 编辑
    handleEdit(row) {
      this.$refs.add.open('edit', row)
    },
    // 详情
    handleInfo(row) {
      this.$refs.info.open(row.id)
    },
    // 复制
    handleCopy(row) {
      this.$refs.add.open('copy', row)
    },
    // 删除
    handleDelete(evt, row) {
      warehouse_orderDeleteApi({id: row.id}).then(res => {
        this.$message.success(res.retmsg)
        this.getList()
      }).catch(err => {
        console.log('err', err)
      })
    },
    // 获取数据
    getData() {
      this.pagination.defaultCurrent = 1
      this.getList()
    },
    // 获取列表
    getList() {
      this.loading = true
      this.params.page = this.pagination.defaultCurrent
      warehouse_orderListApi(this.params).then(res => {
        this.pagination.total = res.count
        this.lists = res.data
      }).catch(err => {
      }).finally(() => {
        this.loading = false
      })
    },
    // 切换分页
    pageChange(pageInfo) {
      const {current, defaultCurrent, defaultPageSize,} = pageInfo
      this.pagination.defaultCurrent = current
      this.getList()
    },
    handleSelectChange(value, {selectedRowData}) {
      this.selectedRowKeys = value;
    },
  },
}
</script>

<style lang="less" scoped>
.book-detail {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: var(--td-radius-medium);
  background-color: #FFFFFF;
}

/deep/ .content-card {

  .t-card__header {
    padding: var(--td-comp-paddingTB-xl) var(--td-comp-paddingLR-xl);
    padding-bottom: 0;
  }

  .t-card__body {
    padding: var(--td-comp-paddingTB-l) var(--td-comp-paddingLR-xl) var(--td-comp-paddingTB-m);
  }

  .setting-btn {
    font-size: 14px;
    font-weight: 400;
    line-height: 19.6px;
    text-align: left;
    color: #005687;
  }

  .invite-btn {
    font-size: 12px;
    font-weight: 400;
    line-height: 16.8px;
    text-align: left;
    color: #005687;

    background-color: #F3FBFF;
    border: 1px solid #005687;
    border-radius: var(--td-radius-default);
  }
}

/deep/ .action-btn {
  width: 126px;
  height: 42px;
  font-size: 16px;
  font-weight: 600;
  line-height: 22.4px;
  text-align: left;
  color: #FFFFFF;

  .t-button__text {
    display: flex;
    align-items: center;
    justify-content: center;

    i {
      z-index: 2;
      font-size: 12px;
      font-weight: bold;
      margin-right: 6px;

      &:after {
        position: absolute;
        display: inline-block;
        content: '';
        top: 50%;
        left: 50%;
        width: 14px;
        height: 14px;
        z-index: -1;
        background-color: #FFFFFF;
        border-radius: var(--td-radius-round);
        transform: translateX(-50%) translateY(-50%);
      }
    }
  }
}

.action-btn1 {
  background-color: #14A54E;
  border: 1px solid #14A54E;

  i {
    color: #14A54E;
  }
}

.action-btn2 {
  background-color: #FF5C46;
  border: 1px solid #DFE3E7;
}

.action-btn3 {
  background-color: #565656;
  border: 1px solid #DFE3E7;
}

.action-btn4 {
  color: black;
  background-color: #F9F9F9;
  border: 1px solid #E1E1E1;
}

/deep/ .filter {
  padding-top: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .t-input, .t-input.t-is-readonly {
    background-color: #F8F8F8;
  }
}

//.import-btn {
//  width: 69px;
//  color: #000000;
//  font-size: 14px;
//  font-weight: 400;
//  line-height: 19.6px;
//  background-color: #F9F9F9;
//  border: 1px solid #E1E1E1;
//}

.income {
  color: #14A54E;
  display: flex;
  align-items: center;

  i {
    width: 17px;
    height: 17px;
    color: #FFFFFF;
    font-size: 12px;
    display: flex;
    margin-left: 8px;
    align-items: center;
    justify-content: center;
    background-color: #14A54E;
    border-radius: var(--td-radius-small);
  }
}

.expenditure {
  color: #FF5C46;
  display: flex;
  align-items: center;

  i {
    width: 17px;
    height: 17px;
    color: #FFFFFF;
    font-size: 12px;
    display: flex;
    margin-left: 8px;
    align-items: center;
    justify-content: center;
    background-color: #FF5C46;
    border-radius: var(--td-radius-small);
  }
}

.footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #F9F9F9;
  padding: var(--td-comp-paddingTB-m) var(--td-comp-paddingLR-xl);
  padding-right: var(--td-comp-paddingLR-xxl);
}
</style>
